Skip to content

Commit

Permalink
Client:同步adt版至studio版
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed May 9, 2017
1 parent c95b571 commit 52471e5
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 51 deletions.
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected Fragment getFragment(int position) {
fragment.setSearchType(EditTextInfoWindow.TYPE_NAME);
return fragment;
case 2:
return SettingFragment.createInstance();
return MineFragment.createInstance();
default:
return MomentListFragment.createInstance();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@
import zuo.biao.apijson.JSONResponse;
import zuo.biao.apijson.StringUtil;
import zuo.biao.library.base.BaseView.OnDataChangedListener;
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
import zuo.biao.library.ui.AlertDialog;
import zuo.biao.library.ui.AlertDialog.OnDialogButtonClickListener;
import zuo.biao.library.ui.WebViewActivity;
import zuo.biao.library.util.CommonUtil;
import zuo.biao.library.util.DownloadUtil;
import zuo.biao.library.util.ImageLoaderUtil;
import zuo.biao.library.util.Log;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
Expand All @@ -36,25 +42,26 @@
import apijson.demo.client.R;
import apijson.demo.client.application.APIJSONApplication;
import apijson.demo.client.base.BaseFragment;
import apijson.demo.client.interfaces.TopBarMenuCallback;
import apijson.demo.client.model.Login;
import apijson.demo.client.model.User;
import apijson.demo.client.util.HttpRequest;

/**设置fragment
* @author Lemon
* @use new SettingFragment(),详细使用见.DemoFragmentActivity(initData方法内)
* @use new MineFragment(),详细使用见.DemoFragmentActivity(initData方法内)
*/
public class SettingFragment extends BaseFragment implements OnClickListener, OnDialogButtonClickListener
, OnHttpResponseListener, OnDataChangedListener {
private static final String TAG = "SettingFragment";
public class MineFragment extends BaseFragment implements OnClickListener, OnDialogButtonClickListener
, OnHttpResponseListener, OnBottomDragListener, TopBarMenuCallback, OnDataChangedListener {
private static final String TAG = "MineFragment";

//与Activity通信<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

/**创建一个Fragment实例
* @return
*/
public static SettingFragment createInstance() {
return new SettingFragment();
public static MineFragment createInstance() {
return new MineFragment();
}

//与Activity通信>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand All @@ -65,17 +72,17 @@ public static SettingFragment createInstance() {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//类相关初始化,必须使用<<<<<<<<<<<<<<<<
super.onCreateView(inflater, container, savedInstanceState);
setContentView(R.layout.setting_fragment);
setContentView(R.layout.mine_fragment);
//类相关初始化,必须使用>>>>>>>>>>>>>>>>

registerObserver(this);

//功能归类分区方法,必须调用<<<<<<<<<<
initView();
initData();
initEvent();
//功能归类分区方法,必须调用>>>>>>>>>>

return view;
}

Expand Down Expand Up @@ -114,6 +121,43 @@ public void run() {
}


private TextView leftMenu;
@SuppressLint("InflateParams")
@Override
public View getLeftMenu(Activity activity) {
if (leftMenu == null) {
leftMenu = (TextView) LayoutInflater.from(activity).inflate(R.layout.top_right_tv, null);
leftMenu.setGravity(Gravity.CENTER);
leftMenu.setText("扫一扫");
leftMenu.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
onDragBottom(false);
}
});
}
return leftMenu;
}

private TextView rightMenu;
@SuppressLint("InflateParams")
@Override
public View getRightMenu(Activity activity) {
if (rightMenu == null) {
rightMenu = (TextView) LayoutInflater.from(activity).inflate(R.layout.top_right_tv, null);
rightMenu.setGravity(Gravity.CENTER);
rightMenu.setText("设置");
rightMenu.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
onDragBottom(true);
}
});
}
return rightMenu;
}

//UI显示区(操作UI,但不存在数据获取或处理代码,也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Expand All @@ -131,15 +175,15 @@ public void run() {
@Override
public void initData() {//必须调用
super.initData();

}

@Override
public void onDataChanged() {
setUser(APIJSONApplication.getInstance().getCurrentUser());
}


/**下载应用
*/
private void downloadApp() {
Expand Down Expand Up @@ -184,13 +228,30 @@ public void initEvent() {//必须调用
findViewById(R.id.llSettingMoment).setOnClickListener(this);
findViewById(R.id.llSettingWallet).setOnClickListener(this);

findViewById(R.id.llSettingSetting).setOnClickListener(this);
findViewById(R.id.llSettingAbout).setOnClickListener(this);
findViewById(R.id.llSettingTest).setOnClickListener(this);
findViewById(R.id.llSettingLogout).setOnClickListener(this);
}


@Override
public void onDragBottom(boolean rightToLeft) {
if (isAlive() == false) {
return;
}

if (rightToLeft) {

toActivity(SettingActivity.createIntent(context));
return;
}

startActivityForResult(ScanActivity.createIntent(context), REQUEST_TO_SCAN);
context.overridePendingTransition(R.anim.bottom_push_in, R.anim.fade);
}



@Override
public void onDialogButtonClick(int requestCode, boolean isPositive) {
if (! isPositive) {
Expand Down Expand Up @@ -218,9 +279,6 @@ public void onDialogButtonClick(int requestCode, boolean isPositive) {
@Override
public void onClick(View v) {//直接调用不会显示v被点击效果
switch (v.getId()) {
case R.id.llSettingSetting:
toActivity(SettingActivity.createIntent(context));
break;
case R.id.llSettingAbout:
toActivity(AboutActivity.createIntent(context));
break;
Expand Down Expand Up @@ -276,6 +334,54 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {

//类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

private static final int REQUEST_TO_SCAN = 1;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}
switch (requestCode) {
case REQUEST_TO_SCAN:
String result = data == null ? null : data.getStringExtra(ScanActivity.RESULT_QRCODE_STRING);
if (StringUtil.isEmpty(result, true) == false) {
if (StringUtil.isUrl(result)) {
int index = result.indexOf("{\"User\":{");
if (index > 0) {
JSONResponse response = new JSONResponse(result.substring(index));
User user = response.getObject(User.class);
long id = user == null ? 0 : user.getId();
if (id > 0) {
toActivity(UserActivity.createIntent(context, id));
break;
}
}
toActivity(WebViewActivity.createIntent(context, "扫描结果", result));
} else {
CommonUtil.copyText(context, result);
}
}
break;
default:
break;
}
}



@Override
public void onDestroy() {
if (leftMenu != null) {
leftMenu.destroyDrawingCache();
leftMenu = null;
}
if (rightMenu != null) {
rightMenu.destroyDrawingCache();
rightMenu = null;
}

super.onDestroy();
}


//类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package apijson.demo.client.activity_fragment;

import zuo.biao.apijson.JSONRequest;
import zuo.biao.library.base.BaseActivity;
import zuo.biao.library.interfaces.OnBottomDragListener;
import zuo.biao.library.manager.CacheManager;
Expand All @@ -31,6 +32,7 @@
import android.widget.TextView;
import apijson.demo.client.R;
import apijson.demo.client.model.User;
import apijson.demo.client.util.HttpRequest;

import com.google.zxing.WriterException;
import com.zxing.encoding.EncodingHandler;
Expand Down Expand Up @@ -145,14 +147,16 @@ public void run() {

private Bitmap qRCodeBitmap;
protected void setQRCode(User user) {
if (user == null) {
Log.e(TAG, "setQRCode user == null" +
" || StringUtil.isNotEmpty(user.getPhone(), true) == false >> return;");
return;
}
// if (user == null) {
// Log.e(TAG, "setQRCode user == null" +
// " || StringUtil.isNotEmpty(user.getPhone(), true) == false >> return;");
// return;
// }

try {
qRCodeBitmap = EncodingHandler.createQRCode(JSON.toJSONString(user)
//不能暴露用户隐私
qRCodeBitmap = EncodingHandler.createQRCode(HttpRequest.URL_GET
+ JSON.toJSONString(new JSONRequest(new apijson.demo.server.model.User(userId)))
, (int) (2 * getResources().getDimension(R.dimen.qrcode_size)));
} catch (WriterException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.view.View;
import android.view.View.OnClickListener;
import apijson.demo.client.R;
import apijson.demo.client.application.APIJSONApplication;

import com.zxing.activity.CaptureActivity;
import com.zxing.view.ViewfinderView;
Expand Down Expand Up @@ -119,10 +120,11 @@ public void initEvent() {//必须调用
@Override
public void onReturnClick(View v) {
finish();
}
}
@Override
public void onForwardClick(View v) {
CommonUtil.toActivity(context, QRCodeActivity.createIntent(context, 1));
CommonUtil.toActivity(context, QRCodeActivity.createIntent(context
, APIJSONApplication.getInstance().getCurrentUserId()));
}

//系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Expand Down
Loading

0 comments on commit 52471e5

Please sign in to comment.