use of android.view.View.OnClickListener in project dynamic-load-apk by singwhatiwanna.
the class MainActivity method generateContentView.
private View generateContentView(final Context context) {
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
layout.setBackgroundColor(Color.parseColor("#F79AB5"));
Button button = new Button(context);
button.setText("Start TestActivity");
layout.addView(button, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DLIntent intent = new DLIntent(getPackageName(), TestFragmentActivity.class);
// 传递Parcelable类型的数据
intent.putExtra("person", new Person("plugin-a", 22));
intent.putExtra("dl_extra", "from DL framework");
startPluginActivityForResult(intent, 0);
}
});
Button button2 = new Button(context);
button2.setText("Start Service");
layout.addView(button2, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
startPluginService(intent);
}
});
Button button3 = new Button(context);
button3.setText("bind Service");
layout.addView(button3, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mConnecton == null) {
mConnecton = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) {
}
public void onServiceConnected(ComponentName name, IBinder binder) {
int sum = ((ITestServiceInterface) binder).sum(5, 5);
Log.e("MainActivity", "onServiceConnected sum(5 + 5) = " + sum);
}
};
}
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
bindPluginService(intent, mConnecton, Context.BIND_AUTO_CREATE);
}
});
Button button4 = new Button(context);
button4.setText("unbind Service");
layout.addView(button4, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mConnecton != null) {
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
unBindPluginService(intent, mConnecton);
mConnecton = null;
}
}
});
return layout;
}
use of android.view.View.OnClickListener in project dynamic-load-apk by singwhatiwanna.
the class TestFragmentActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
// 输出Parcelable对象信息
Toast.makeText(that, getIntent().getExtras().getParcelable("person").toString(), Toast.LENGTH_SHORT).show();
Log.d(TAG, "### person info : " + getIntent().getExtras().getParcelable("person"));
TestButton button = (TestButton) findViewById(R.id.button1);
button.setText(that.getResources().getString(R.string.test));
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(that, "quit", Toast.LENGTH_SHORT).show();
that.setResult(RESULT_FIRST_USER);
that.finish();
}
});
mEditText = (EditText) findViewById(R.id.editText1);
mEditText.setText(R.string.hello_world);
mShowFragmentButton = (Button) findViewById(R.id.show_fragment);
mShowFragmentButton.setOnClickListener(this);
mStartPluginB = (Button) findViewById(R.id.start_plugin_b);
mStartPluginB.setOnClickListener(this);
}
use of android.view.View.OnClickListener in project android-demos by novoda.
the class SelfContainedTabHost method goToTab2.
private OnClickListener goToTab2() {
return new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.novoda.TAB");
intent.putExtra("tab", 1);
sendBroadcast(intent);
}
};
}
use of android.view.View.OnClickListener in project android-demos by novoda.
the class SelfContainedTabHost method goToTab1.
private OnClickListener goToTab1() {
return new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.novoda.TAB");
intent.putExtra("tab", 0);
sendBroadcast(intent);
}
};
}
use of android.view.View.OnClickListener in project VideoRecorder by qdrzwd.
the class Util method showDialog.
/**
* 公共弹窗
*
* @param context
* :Context 传入当前调用该方法的activity实例
* @param msg
* :String 要显示的显示文字
* @param type
* :int 显示类型1:仅为确定,2:有“确定”、“取消”两个操作
* @param handler
* :Handler 传入的需要回调的handler信息,可作为回调方法是用,msg.what = 1时为操作完成状态符
*/
public static void showDialog(Context context, String title, String content, int type, final Handler handler) {
final Dialog dialog = new Dialog(context, R.style.Dialog_loading);
dialog.setCancelable(true);
// 设置像是内容模板
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.global_dialog_tpl, null);
Button confirmButton = (Button) view.findViewById(// 确认
R.id.setting_account_bind_confirm);
Button cancelButton = (Button) view.findViewById(// 取消
R.id.setting_account_bind_cancel);
TextView dialogTitle = (TextView) view.findViewById(// 标题
R.id.global_dialog_title);
// 中竖线
View lineHoriCenter = view.findViewById(R.id.line_hori_center);
// 默认隐藏取消按钮
confirmButton.setVisibility(View.GONE);
lineHoriCenter.setVisibility(View.GONE);
TextView textView = (TextView) view.findViewById(R.id.setting_account_bind_text);
// 设置对话框的宽度
Window dialogWindow = dialog.getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = (int) (context.getResources().getDisplayMetrics().density * 288);
dialogWindow.setAttributes(lp);
// 设置显示类型
if (type != 1 && type != 2) {
type = 1;
}
// 设置标题
dialogTitle.setText(title);
// 设置提示内容
textView.setText(content);
// 确认按钮操作
if (type == 1 || type == 2) {
confirmButton.setVisibility(View.VISIBLE);
confirmButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (handler != null) {
Message msg = handler.obtainMessage();
msg.what = 1;
handler.sendMessage(msg);
}
dialog.dismiss();
}
});
}
// 取消按钮事件
if (type == 2) {
cancelButton.setVisibility(View.VISIBLE);
lineHoriCenter.setVisibility(View.VISIBLE);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (handler != null) {
Message msg = handler.obtainMessage();
msg.what = 0;
handler.sendMessage(msg);
}
dialog.dismiss();
}
});
}
dialog.addContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// 点击返回键关闭
dialog.setCancelable(true);
// 点击外部关闭
dialog.setCanceledOnTouchOutside(true);
dialog.show();
}
Aggregations