导航栏跳转解决

master
huan 2 years ago
parent 07ee79198d
commit c2be621bf2

@ -69,7 +69,7 @@
</profile-state>
</entry>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -11,9 +11,11 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.orangesale.cn.activity.IndexActivity;
import com.orangesale.cn.activity.OrangeDatabase;
import com.orangesale.cn.activity.RegisterActivity;
import com.orangesale.cn.activity.UserActivity;
import com.orangesale.cn.fragment.IndexFragment;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button registerButton, loginButton;
@ -35,7 +37,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
break;
case R.id.login:
if (validateLogin()) {
Intent intent1 = new Intent(MainActivity.this, UserActivity.class);
Intent intent1 = new Intent(MainActivity.this, IndexActivity.class);
Bundle bundle = new Bundle();
OrangeDatabase orangeDatabase = new OrangeDatabase(MainActivity.this);
bundle.putString("username", usernameText.getText().toString());

@ -3,7 +3,7 @@ package com.orangesale.cn.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.app.FragmentTransaction;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
@ -14,6 +14,7 @@ import com.orangesale.cn.fragment.IndexFragment;
import com.orangesale.cn.fragment.PersonFragment;
import com.orangesale.cn.fragment.ProductFragment;
import com.orangesale.cn.fragment.ShoppingFragment;
import com.orangesale.cn.fragment.TimeService;
public class IndexActivity extends Activity implements View.OnClickListener {
@ -21,7 +22,6 @@ public class IndexActivity extends Activity implements View.OnClickListener {
private ProductFragment productFragment;
private ShoppingFragment shoppingFragment;
private IndexFragment indexFragment;
private PersonFragment personFragment;
private LinearLayout indexLine;
@ -29,12 +29,9 @@ public class IndexActivity extends Activity implements View.OnClickListener {
private LinearLayout shoppingLine;
private LinearLayout personLine;
public IndexActivity(LinearLayout indexLine,LinearLayout productLine, LinearLayout shoppingLine, LinearLayout personLine) {
this.productLine = productLine;
this.personLine = personLine;
this.indexLine = indexLine;
this.shoppingLine = shoppingLine;
}
Intent timeServiceIntent;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@ -42,6 +39,8 @@ public class IndexActivity extends Activity implements View.OnClickListener {
setContentView(R.layout.activity_main);
init();
initIndexFragment();
Thread thread = new Thread(runnable);
thread.start();
}
private void init() {
@ -74,7 +73,7 @@ public class IndexActivity extends Activity implements View.OnClickListener {
initshoppingFragment();
break;
case R.id.content_pearson:
case R.id.content_person:
//注册验证方法
initpersonFragment();
break;
@ -96,7 +95,7 @@ public class IndexActivity extends Activity implements View.OnClickListener {
}
private void initshoppingFragment() {
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (shoppingFragment == null) {
shoppingFragment = new ShoppingFragment();
}
@ -114,13 +113,22 @@ public class IndexActivity extends Activity implements View.OnClickListener {
}
private void initIndexFragment() {
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (indexFragment == null) {
indexFragment = new IndexFragment();
}
transaction.replace(R.id.main_content,productFragment);
transaction.replace(R.id.main_content,indexFragment);
transaction.commit();
}
Runnable runnable = () -> {
timeServiceIntent = new Intent(IndexActivity.this, TimeService.class);
startService(timeServiceIntent);
};
@Override
protected void onDestroy() {
super.onDestroy();
stopService(timeServiceIntent);
}
}

@ -16,6 +16,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.lljjcoder.citypickerview.widget.CityPicker;
import com.orangesale.cn.MainActivity;
import com.orangesale.cn.R;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
@ -43,6 +44,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
usernameEdit = findViewById(R.id.reg_username);
passwordEdit = findViewById(R.id.reg_password);
surePasswordEdit = findViewById(R.id.reg_sure_password);
regButton = findViewById(R.id.reg_register);
regButton.setOnClickListener(this);
sexGroup = findViewById(R.id.sex);
@ -56,6 +58,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
case R.id.reg_province:
initCityPicker();
cityPicker.show();
break;
case R.id.reg_register:
//注册验证方法
@ -127,7 +130,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
OrangeDatabase orangeDatabase = new OrangeDatabase(RegisterActivity.this);
SQLiteDatabase sqLiteDatabase = orangeDatabase.getWritableDatabase();
insertData(sqLiteDatabase, bundle);
Intent intent = new Intent(RegisterActivity.this, UserActivity.class);
Intent intent = new Intent(RegisterActivity.this, IndexActivity.class);
intent.putExtras(bundle);
startActivity(intent);
} else {

@ -71,8 +71,14 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
product1.setProductName("褚橙");
product1.setProductPrice(new BigDecimal("29.9"));
Product product2 = new Product();
product1.setImageUrlId(R.drawable.qicheng);
product1.setProductName("脐橙");
product1.setProductPrice(new BigDecimal("29.9"));
productList.add(product);
productList.add(product1);
productList.add(product2);
}
}

@ -0,0 +1,89 @@
package com.orangesale.cn.fragment;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.orangesale.cn.R;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TimeService extends Service {
private static Timer timer = null;
private NotificationManager manager;
private NotificationCompat.Builder builder;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
/** 清除通知 */
private void cleanAllNotification() {
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancelAll();
if (timer != null) {
timer.cancel();
timer = null;
}
}
/**
*
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
long period = 60 * 1000; //1分钟一个周期
if (timer == null) {
timer = new Timer();
}
timer.schedule(new TimerTask() {
@Override
public void run() {
/**
* NotificationChannelandroid8.0ApptargetSDKVersion>=26
* channel
* Failed to post notification on channel null
*/
NotificationChannel channel = new NotificationChannel("channel", "通知", NotificationManager.IMPORTANCE_DEFAULT);
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
builder = new NotificationCompat.Builder(TimeService.this);
builder.setContentTitle("提醒系统当前时间");
builder.setSmallIcon(R.drawable.chengzi);
builder.setChannelId("channel");
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
builder.setContentText("系统当前时间为:" + formatter.format(date));
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
Notification notification = builder.build();
manager.notify(1, notification);
}
}, 0, period);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
cleanAllNotification();
System.out.println("onDestory: cleanAllNotification ");
}
}

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

@ -96,7 +96,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/juzi"
android:id="@+id/shuiguo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -106,7 +106,7 @@
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/juzi" />
android:src="@drawable/shuiguo" />
<TextView
android:layout_width="wrap_content"

@ -93,7 +93,7 @@
<!--个人-->
<LinearLayout
android:id="@+id/content_pearson"
android:id="@+id/content_person"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -104,7 +104,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/pearson" />
android:src="@drawable/person" />
<TextView
android:layout_width="wrap_content"

Loading…
Cancel
Save