@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.button = (Button) findViewById(R.id.button); this.textView = (TextView) findViewById(R.id.textView); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setAction(Intents.Scan.ACTION); intent.putExtra(Intents.Scan.CHARACTER_SET, "utf-8"); intent.putExtra(Intents.Scan.WIDTH, dip2px(220)); intent.putExtra(Intents.Scan.HEIGHT, dip2px(220)); intent.setClass(MainActivity.this, CaptureActivity.class); startActivityForResult(intent, REQUEST_CODE); } }); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_refresh) { if(!TextUtils.equals(CURRENT_IP,DEFAULT_IP)){ createWeexInstance(); return true; } } else if (id == R.id.action_scan) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show(); } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMARA_PERMISSION_REQUEST_CODE); } } else { startActivity(new Intent(this, CaptureActivity.class)); } return true; } return super.onOptionsItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_refresh) { if(!TextUtils.equals(CURRENT_IP,DEFAULT_IP)){ createWeexInstance(); if(TextUtils.equals(CURRENT_IP,DEFAULT_IP)){ renderPage(WXFileUtils.loadAsset("index.js", this),WEEX_INDEX_URL); }else{ renderPageByURL(WEEX_INDEX_URL); } mProgressBar.setVisibility(View.VISIBLE); return true; } } else if (id == R.id.action_scan) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show(); } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE); } } else { startActivity(new Intent(this, CaptureActivity.class)); } return true; } return super.onOptionsItemSelected(item); }
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { startActivity(new Intent(this, CaptureActivity.class)); } else { Toast.makeText(this, "request camara permission fail!", Toast.LENGTH_SHORT).show(); } }
public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) { ParsedResult result = parseResult(rawResult); switch (result.getType()) { case ADDRESSBOOK: return new AddressBookResultHandler(activity, result); case EMAIL_ADDRESS: return new EmailAddressResultHandler(activity, result); case PRODUCT: return new ProductResultHandler(activity, result, rawResult); case URI: return new URIResultHandler(activity, result); case WIFI: return new WifiResultHandler(activity, result); case GEO: return new GeoResultHandler(activity, result); case TEL: return new TelResultHandler(activity, result); case SMS: return new SMSResultHandler(activity, result); case CALENDAR: return new CalendarResultHandler(activity, result); case ISBN: return new ISBNResultHandler(activity, result, rawResult); default: return new TextResultHandler(activity, result, rawResult); } }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { if (adapter.getItem(position).getResult() != null) { Intent intent = new Intent(this, CaptureActivity.class); intent.putExtra(Intents.History.ITEM_NUMBER, position); setResult(Activity.RESULT_OK, intent); finish(); } }
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == CAMARA_PERMISSION_REQUEST_CODE && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { startActivity(new Intent(this, CaptureActivity.class)); } else { Toast.makeText(this, "request camara permission fail!", Toast.LENGTH_SHORT).show(); } }