SHARE
TWEET

Untitled

a guest Nov 14th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.harukaedu.lms.bases;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6.  
  7. import androidx.annotation.LayoutRes;
  8. import androidx.annotation.Nullable;
  9. import androidx.appcompat.app.AppCompatActivity;
  10. import androidx.databinding.DataBindingUtil;
  11. import androidx.databinding.ViewDataBinding;
  12.  
  13. public abstract class BaseDataBindingActivity<VDB extends ViewDataBinding> extends AppCompatActivity {
  14.     @LayoutRes
  15.     protected abstract int getContentView();
  16.     protected abstract void initViews();
  17.     protected abstract void initDataBinding(VDB bindingData);
  18.  
  19.     @Override
  20.     protected void onCreate(@Nullable Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         onPreCreateView(savedInstanceState);
  23.         VDB binding = DataBindingUtil.setContentView(this, getContentView());
  24.         initDataBinding(binding);
  25.  
  26.         if (getIntent().getExtras() != null)
  27.             collectExtras(getIntent().getExtras());
  28.  
  29.         if (savedInstanceState != null)
  30.             onLoadSavedInstanceState(savedInstanceState);
  31.  
  32.         onPostCreateView(savedInstanceState);
  33.     }
  34.  
  35.     protected void changePage(Class<? extends Activity> cls){
  36.         changePage(cls, (Bundle) null, (Integer) null);
  37.     }
  38.  
  39.     protected void changePage(Class<? extends Activity> cls, Bundle bundle){
  40.         changePage(cls, bundle, (Integer) null);
  41.     }
  42.  
  43.     protected void changePage(Class<? extends Activity> cls, Integer... flags){
  44.         changePage(cls, null, flags);
  45.     }
  46.  
  47.     protected void changePage(Class<? extends Activity> cls, Bundle bundle, Integer... flags){
  48.         Intent intent = new Intent(this, cls);
  49.  
  50.         if (bundle != null)
  51.             intent.putExtras(bundle);
  52.  
  53.         if (flags != null){
  54.             for (Integer flag : flags){
  55.                 if (flag != null)
  56.                     intent.addFlags(flag);
  57.             }
  58.         }
  59.  
  60.         startActivity(intent);
  61.     }
  62.  
  63.     protected void changePageOnResult(Class<? extends Activity> cls, int requestCode){
  64.         changePageOnResult(cls, null, requestCode);
  65.     }
  66.  
  67.     protected void changePageOnResult(Class<? extends Activity> cls, Bundle bundle, int requestCode){
  68.         Intent intent = new Intent(this, cls);
  69.  
  70.         if (bundle != null)
  71.             intent.putExtras(bundle);
  72.  
  73.         startActivityForResult(intent, requestCode);
  74.     }
  75.  
  76.     protected void collectExtras(Bundle bundle){
  77.         //call when getIntent().getExtras() is not null
  78.     }
  79.  
  80.     protected void onPreCreateView(Bundle savedInstanceState){
  81.         //call before setContentView
  82.     }
  83.  
  84.     protected void onLoadSavedInstanceState(Bundle savedInstanceState){
  85.         //call when savedInstanceState is not null
  86.     }
  87.  
  88.     protected void onPostCreateView(Bundle savedInstanceState){
  89.         //call after initViews()
  90.     }
  91. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top