Created
May 16, 2016 16:01
-
-
Save medJemmoudi/86816f3350bd77faf4aacb8658e45ff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.wwls.dimarabah; | |
import android.app.AlertDialog; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.os.Bundle; | |
import android.os.PersistableBundle; | |
import android.os.Vibrator; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.Toast; | |
import com.google.zxing.integration.android.IntentIntegrator; | |
/** | |
* Created by Mohammed on 17/02/2016. | |
*/ | |
public abstract class BaseActivity extends AppCompatActivity { | |
private static final long VIBRATION_TIME = 500; | |
@Override | |
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { | |
super.onCreate(savedInstanceState, persistentState); | |
} | |
protected void launchScanner () { | |
IntentIntegrator integrator = new IntentIntegrator(this); | |
integrator.setBeepEnabled(false); | |
integrator.setPrompt(getString(R.string.scan_card)); | |
integrator.initiateScan(); | |
} | |
protected void makeToast(String contents) { | |
Toast.makeText(this, contents, Toast.LENGTH_LONG).show(); | |
} | |
protected void showAlert ( String message ) { | |
AlertDialog.Builder builder1 = new AlertDialog.Builder(this); | |
builder1.setMessage( message ); | |
builder1.setCancelable(true); | |
builder1.setPositiveButton("Ok", | |
new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialog, int id) { | |
dialog.cancel(); | |
} | |
} | |
); | |
AlertDialog alert11 = builder1.create(); | |
alert11.show(); | |
} | |
/** | |
* Things should be done before scanning | |
* @author Mohammed JEMMOUDI | |
* @return void | |
*/ | |
abstract protected void beforeScan(); | |
/** | |
* Things should be done after scanning | |
* @author Mohammed JEMMOUDI | |
* @return void | |
*/ | |
abstract protected void afterScan(); | |
/** | |
* launch scanning process with some extra jobs (before & after scan) | |
* @author Mohammed JEMMOUDI | |
* @return void | |
*/ | |
protected void customScan( String prompt ) { | |
beforeScan(); | |
IntentIntegrator integrator = new IntentIntegrator(this); | |
integrator.setBeepEnabled(false); | |
integrator.setPrompt(getString(R.string.scan_card)); | |
integrator.initiateScan(); | |
afterScan(); | |
} | |
protected void vibrate() { | |
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); | |
v.vibrate(VIBRATION_TIME); | |
} | |
private boolean hasActiveConnection () { | |
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo ni = cm.getActiveNetworkInfo(); | |
// There are no active networks. | |
return ni != null && ni.isConnected(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment