آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

کد هایی که نوشتم کجاش مشکل داره ؟ میشه کمکم کنین؟

S.M.N  9 سال پیش  9 سال پیش
0 0

 

public class MainActivity extends BaseScannerActivity
implements NavigationView.OnNavigationItemSelectedListener, MessageDialogFragment.MessageDialogListener,
ZXingScannerView.ResultHandler, FormatSelectorDialogFragment.FormatSelectorDialogListener,
CameraSelectorDialogFragment.CameraSelectorDialogListener {
public static String ok_scan = "", rej_scanner = "";
EditText edt_Price;


private static final int ZXING_CAMERA_PERMISSION = 1;
private Class<?> mClss;
String BarCode = "0";
private static final String FLASH_STATE = "FLASH_STATE";
private static final String AUTO_FOCUS_STATE = "AUTO_FOCUS_STATE";
private static final String SELECTED_FORMATS = "SELECTED_FORMATS";
private static final String CAMERA_ID = "CAMERA_ID";
private ZXingScannerView mScannerView;
private boolean mFlash;
private boolean mAutoFocus;
private ArrayList<Integer> mSelectedIndices;
private int mCameraId = -1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState != null) {
mFlash = savedInstanceState.getBoolean(FLASH_STATE, false);
mAutoFocus = savedInstanceState.getBoolean(AUTO_FOCUS_STATE, true);
mSelectedIndices = savedInstanceState.getIntegerArrayList(SELECTED_FORMATS);
mCameraId = savedInstanceState.getInt(CAMERA_ID, -1);
} else {
mFlash = false;
mAutoFocus = true;
mSelectedIndices = null;
mCameraId = -1;
}


edt_Price = (EditText) findViewById(R.id.input_Price);
setContentView(R.layout.activity_main);
setupToolbar();

ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
try {
mScannerView = new ZXingScannerView(this);
}
catch (Exception e){Toast.makeText(MainActivity.this, "Exeption Called !!!", Toast.LENGTH_SHORT).show();}

setupFormats();
try {
contentFrame.addView(mScannerView);

}
catch (Exception e){Toast.makeText(MainActivity.this, "Exeption Called !!!", Toast.LENGTH_SHORT).show();}
EditText ok_scanner = (EditText) findViewById(R.id.ok_scanner);

ok_scan = ok_scanner.getText().toString();

EditText reject_scanner = (EditText) findViewById(R.id.reject_scanner);

rej_scanner = reject_scanner.getText().toString();

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);



findViewById(R.id.BtnPay).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Toast.makeText(MainActivity.this,R.string.redirect_pay_page, Toast.LENGTH_SHORT).show();
}
});


findViewById(R.id.reject_pay).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,R.string.reject_Barcode, Toast.LENGTH_SHORT).show();
try {

// Toast.makeText(MainActivity.this,R.string.ErrorInReadBarCode, Toast.LENGTH_SHORT).show();

mScannerView.resumeCameraPreview(MainActivity.this);

EditText edts=(EditText) findViewById(R.id.input_BarCode);

edts.setText("".toString());

EditText edtp=(EditText) findViewById(R.id.input_Price);

edtp.setText("".toString());
}

catch (Exception e) {
Toast.makeText(MainActivity.this, "Exeption Called !!!", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(MainActivity.this,ReLoad.class);
MainActivity.this.startActivity(intent);
}
}
});

CamerPerision();



}
public void CamerPerision()
{
try {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CAMERA},
1);
}
catch (Exception e)
{
Toast.makeText(this,R.string.cameraSetting, Toast.LENGTH_LONG).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case 1: {

// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
Toast.makeText(MainActivity.this,R.string.cameraError, Toast.LENGTH_SHORT).show();
}
return;
}

// other 'case' lines to check for other
// permissions this app might request
}
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera(mCameraId);
// mScannerView.setFlash(mFlash);
// mScannerView.setAutoFocus(mAutoFocus);


}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(FLASH_STATE, mFlash);
outState.putBoolean(AUTO_FOCUS_STATE, mAutoFocus);
outState.putIntegerArrayList(SELECTED_FORMATS, mSelectedIndices);
outState.putInt(CAMERA_ID, mCameraId);
}


public void launchActivity(Class<?> clss) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
mClss = clss;
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA}, ZXING_CAMERA_PERMISSION);
} else {
Intent intent = new Intent(this, clss);
startActivity(intent);
}
}

public void launchFullActivity(View v) {
launchActivity(FullScannerActivity.class);
}


@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.+

MenuItem menuItem;

if (mFlash) {
menuItem = menu.add(Menu.NONE, R.id.menu_flash, 0, R.string.flash_on);
} else {
menuItem = menu.add(Menu.NONE, R.id.menu_flash, 0, R.string.flash_off);
}
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_NEVER);


if (mAutoFocus) {
menuItem = menu.add(Menu.NONE, R.id.menu_auto_focus, 0, R.string.auto_focus_on);
} else {
menuItem = menu.add(Menu.NONE, R.id.menu_auto_focus, 0, R.string.auto_focus_off);
}
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_NEVER);

menuItem = menu.add(Menu.NONE, R.id.menu_formats, 0, R.string.formats);
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_NEVER);

menuItem = menu.add(Menu.NONE, R.id.menu_camera_selector, 0, R.string.select_camera);
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_NEVER);

return super.onCreateOptionsMenu(menu);


/*getMenuInflater().inflate(R.menu.main, menu);
return true;*/
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.menu_flash:
mFlash = !mFlash;
if (mFlash) {
item.setTitle(R.string.flash_on);
} else {
item.setTitle(R.string.flash_off);
}
mScannerView.setFlash(mFlash);
return true;
case R.id.menu_auto_focus:
mAutoFocus = !mAutoFocus;
if (mAutoFocus) {
item.setTitle(R.string.auto_focus_on);
} else {
item.setTitle(R.string.auto_focus_off);
}
mScannerView.setAutoFocus(mAutoFocus);
return true;
case R.id.menu_formats:
DialogFragment fragment = FormatSelectorDialogFragment.newInstance(this, mSelectedIndices);
fragment.show(getSupportFragmentManager(), "format_selector");
return true;
case R.id.menu_camera_selector:
mScannerView.stopCamera();
DialogFragment cFragment = CameraSelectorDialogFragment.newInstance(this, mCameraId);
cFragment.show(getSupportFragmentManager(), "camera_selector");
return true;
default:
return super.onOptionsItemSelected(item);
}

}

@Override
public void handleResult(Result rawResult) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Exeption Called !!!", Toast.LENGTH_SHORT).show();

}

try {
BarCode = rawResult.getText();

EditText edt = (EditText) findViewById(R.id.input_BarCode);
edt.setText(BarCode);
} catch (Exception e) {
//Show Error CanNot Enter Bar Code To Edit Text
Toast.makeText(this,R.string.ErrorInReadBarCode, Toast.LENGTH_SHORT).show();
mScannerView.resumeCameraPreview(this);
}

}

public void showMessageDialog(String message) {
DialogFragment fragment = MessageDialogFragment.newInstance("Scan Results", message, this);
fragment.show(getSupportFragmentManager(), "scan_results");
}

public void closeMessageDialog() {
closeDialog("scan_results");
}

public void closeFormatsDialog() {
closeDialog("format_selector");
}

public void closeDialog(String dialogName) {
FragmentManager fragmentManager = getSupportFragmentManager();
DialogFragment fragment = (DialogFragment) fragmentManager.findFragmentByTag(dialogName);
if (fragment != null) {
fragment.dismiss();
}
}

@Override
public void onDialogPositiveClick(DialogFragment dialog) {
// Resume the camera
mScannerView.resumeCameraPreview(this);
}

@Override
public void onDialogNegativeClick(DialogFragment dialog) {
// Cancle Payment
mScannerView.resumeCameraPreview(this);
}

@Override
public void onFormatsSaved(ArrayList<Integer> selectedIndices) {
mSelectedIndices = selectedIndices;
setupFormats();
}

@Override
public void onCameraSelected(int cameraId) {

mCameraId = cameraId;
mScannerView.startCamera(mCameraId);
mScannerView.setFlash(mFlash);
mScannerView.setAutoFocus(mAutoFocus);

}

public void setupFormats() {
List<BarcodeFormat> formats = new ArrayList<BarcodeFormat>();
if (mSelectedIndices == null || mSelectedIndices.isEmpty()) {
mSelectedIndices = new ArrayList<Integer>();
for (int i = 0; i < ZXingScannerView.ALL_FORMATS.size(); i++) {
mSelectedIndices.add(i);
}
}

for (int index : mSelectedIndices) {
formats.add(ZXingScannerView.ALL_FORMATS.get(index));
}
if (mScannerView != null) {
mScannerView.setFormats(formats);
}
}

@Override
public void onPause() {

super.onPause();
mScannerView.stopCamera();
closeMessageDialog();
closeFormatsDialog();

}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_profile) {
// Handle the camera action

} else if (id == R.id.nav_money) {

} else if (id == R.id.nav_info) {
Intent intent=new Intent(MainActivity.this,User_Information.class);
MainActivity.this.startActivity(intent);

} else if (id == R.id.nav_messages) {

} else if (id == R.id.nav_add_account) {
Intent intent=new Intent(MainActivity.this,User_Add_Account.class);
MainActivity.this.startActivity(intent);
} else if (id == R.id.nav_charge_account) {

}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}



}

0 0
هر چند زیاد سر در نمیارم ولی بهتر نبود خودتون یه بررسی میکردید که اشکال از کدوم بخش هست!! و فقط همون بخشو مینوشتید (9 سال پیش)
0 0
اول باید بگین این کد چیکار میکنه دوم لاگ بزارین ببینین کدوم بخش ها اجرا میشه کجا ها نمیشه (9 سال پیش)
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .