SHARE
TWEET

Untitled

a guest Jan 25th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class LoginActivity extends AppCompatActivity {
  2.  
  3.     private EditText edtUsername;
  4.     private EditText edtPassword;
  5.     private Button btnLogin;
  6.  
  7.     // store username & password in SQLite db
  8.     // taken from https://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
  9.     SessionManager session;
  10.  
  11.     // manage stored items in SQLite
  12.     private DatabaseHelper db;
  13.  
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.  
  18.         spinner.setAdapter(adapter);
  19.  
  20.         db = new DatabaseHelper(this);
  21.  
  22.         session = new SessionManager(getApplicationContext());
  23.         if (session.isLoggedIn()){
  24.             IntentIntegrator scanIntegrator = new IntentIntegrator(LoginActivity.this);
  25.             scanIntegrator.setOrientationLocked(false);
  26.             scanIntegrator.initiateScan();
  27.         }
  28.  
  29.         edtUsername = (EditText) findViewById(R.id.edtName);
  30.         edtPassword = (EditText) findViewById(R.id.edtPassword);
  31.         btnLogin = (Button) findViewById(R.id.btnLogin);
  32.     }
  33.  
  34.  
  35.     @Override
  36.     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  37.         IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
  38.         if (scanningResult != null){
  39.             String scanContent = scanningResult.getContents();
  40.             String[] data = parseContent(scanContent);
  41.  
  42.             db.insertItem(new Item(data[0], data[1], data[2]));
  43.  
  44.             Intent iii = new Intent(LoginActivity.this, ScanResultActivity.class);
  45.             startActivity(iii);
  46.         }
  47.     }
  48.  
  49. }
  50.    
  51. public class ScanResultActivity extends AppCompatActivity {
  52.  
  53.     private RecyclerView recView;
  54.     private ItemAdapter mAdapter;
  55.     private DatabaseHelper db;
  56.     private List<Item> itemList;
  57.  
  58.     @Override
  59.     protected void onCreate(Bundle savedInstanceState) {
  60.         super.onCreate(savedInstanceState);
  61.         setContentView(R.layout.activity_scan_result);
  62.  
  63.         recView = (RecyclerView) findViewById(R.id.recycler_view);
  64.         itemList = new ArrayList<>();
  65.  
  66.         db = new DatabaseHelper(this);
  67.         itemList.addAll(db.getAllItems());
  68.  
  69.         mAdapter = new ItemAdapter(this, itemList);
  70.         RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
  71.         recView.setLayoutManager(mLayoutManager);
  72.         recView.setItemAnimator(new DefaultItemAnimator());
  73.         recView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
  74.         recView.setAdapter(mAdapter);
  75.     }
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top