Skip to content

Commit

Permalink
添加登录界面
Browse files Browse the repository at this point in the history
  • Loading branch information
robbyzhaox committed Aug 12, 2015
1 parent 76caec4 commit 8d041a1
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 11 deletions.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
android:name="android.hardware.camera2"
android:required="true" />

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<application
android:name=".test.MyApplication"
android:allowBackup="true"
Expand Down Expand Up @@ -45,6 +47,11 @@
</intent-filter>
</activity>

<receiver android:name=".base.ForceOfflineReceiver">
<intent-filter>
<action android:name="com.telchina.wx.FORCE_OFFLINE" />
</intent-filter>
</receiver>
</application>

</manifest>
2 changes: 0 additions & 2 deletions app/src/main/java/com/telchina/wx/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ public void onClick(View v) {
String password = passwordEditText.getText().toString();

if ("admin".equals(account) && "123".equals(password)) {

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
} else {
Toast.makeText(LoginActivity.this, "wrong", Toast.LENGTH_LONG).show();
}

}
}
10 changes: 6 additions & 4 deletions app/src/main/java/com/telchina/wx/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
Expand All @@ -14,7 +13,7 @@
import android.view.ViewConfiguration;
import android.view.Window;

import com.telchina.wx.R;
import com.telchina.wx.base.BaseActivity;
import com.telchina.wx.base.ChangeColorIconWithText;
import com.telchina.wx.base.TabFragment;

Expand All @@ -27,8 +26,7 @@
import java.util.ArrayList;
import java.util.List;


public class MainActivity extends FragmentActivity implements
public class MainActivity extends BaseActivity implements
View.OnClickListener,
ViewPager.OnPageChangeListener {

Expand Down Expand Up @@ -137,6 +135,10 @@ public boolean onOptionsItemSelected(MenuItem item) {

Intent intent = new Intent(NEWS);
startActivity(intent);
} else if (item.getItemId() == R.id.action_force_offline) {
//强制下线
Intent intent = new Intent("com.telchina.wx.FORCE_OFFLINE");
sendBroadcast(intent);
}

return super.onOptionsItemSelected(item);
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/com/telchina/wx/base/ForceOfflineReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.telchina.wx.base;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.WindowManager;

import com.telchina.wx.LoginActivity;
import com.telchina.wx.R;

/**
* Created by zg on 2015/8/12.
*/
public class ForceOfflineReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
AlertDialog.Builder builder=new AlertDialog.Builder(context);
builder.setTitle(R.string.force_offline_title);
builder.setMessage(R.string.force_offline_message);
builder.setCancelable(false);
builder.setPositiveButton(R.string.force_offline_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCollector.finishAll();
Intent intent = new Intent(context, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});

AlertDialog dialog=builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/telchina/wx/news/NewsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ public View getView(int position, View convertView, ViewGroup parent) {
return view;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Window;

import com.telchina.wx.R;
import com.telchina.wx.base.BaseActivity;

public class NewsContentActivity extends FragmentActivity {
public class NewsContentActivity extends BaseActivity {

public static void actionStart(Context context, String newsTitle, String newsContent) {
Intent intent = new Intent(context, NewsContentActivity.class);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/telchina/wx/news/NewsListActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.telchina.wx.news;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.telchina.wx.R;
import com.telchina.wx.base.BaseActivity;

/**
* Created by zg on 2015/8/9.
*/
public class NewsListActivity extends FragmentActivity {
public class NewsListActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
android:icon="@mipmap/menu_feedback_icon"
android:title="@string/menu_feedback" />

<item
android:id="@+id/action_force_offline"
android:icon="@mipmap/menu_add_icon"
android:title="@string/force_offline" />

</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
<string name="login_password_hint">请输入您的密码</string>
<string name="login_button_label">登录</string>

<string name="force_offline">强制下线</string>
<string name="force_offline_button">确定</string>
<string name="force_offline_title">警告</string>
<string name="force_offline_message">账号在别处登录,系统将强制下线,请尝试重新登录</string>

</resources>

0 comments on commit 8d041a1

Please sign in to comment.