use of com.instructure.loginapi.login.adapter.SnickerDoodleAdapter in project instructure-android by instructure.
the class OAuthWebLogin method eatSnickerDoodles.
/**
* Adds a simple login method for devs. To add credentials add your snickers (credentials) to the snickers.json
* Slide the drawer out from the right to have a handy one click login. FYI: Only works on Debug.
* Sample Format is:
*
* [
* {
* "password":"password",
* "subtitle":"subtitle",
* "title":"title",
* "username":"username"
* },
* ...
* ]
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private void eatSnickerDoodles() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
Writer writer = new StringWriter();
try {
InputStream is = getResources().openRawResource(getResources().getIdentifier("snickers", "raw", getPackageName()));
char[] buffer = new char[1024];
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
is.close();
} catch (Exception e) {
// Do Nothing
}
String jsonString = writer.toString();
if (jsonString != null && jsonString.length() > 0) {
ArrayList<SnickerDoodle> snickerDoodles = new Gson().fromJson(jsonString, new TypeToken<ArrayList<SnickerDoodle>>() {
}.getType());
if (snickerDoodles.size() == 0) {
findViewById(R.id.drawerEmptyView).setVisibility(View.VISIBLE);
findViewById(R.id.drawerEmptyText).setVisibility(View.VISIBLE);
return;
}
web.getSettings().setDomStorageEnabled(true);
web.setWebChromeClient(new WebChromeClient());
mDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true));
mDrawerRecyclerView.setAdapter(new SnickerDoodleAdapter(snickerDoodles, new SnickerDoodleAdapter.SnickerCallback() {
@Override
public void onClick(SnickerDoodle snickerDoodle) {
mDrawerLayout.closeDrawers();
final String js = "javascript: { " + "document.getElementsByName('pseudonym_session[unique_id]')[0].value = '" + snickerDoodle.username + "'; " + "document.getElementsByName('pseudonym_session[password]')[0].value = '" + snickerDoodle.password + "'; " + "document.getElementsByClassName('btn')[0].click(); " + "};";
web.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
final String js = "javascript: { " + "document.getElementsByClassName('btn')[0].click();" + "};";
web.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
}
});
}
});
}
}, 750);
}
}));
} else {
findViewById(R.id.drawerEmptyView).setVisibility(View.VISIBLE);
findViewById(R.id.drawerEmptyText).setVisibility(View.VISIBLE);
}
}
use of com.instructure.loginapi.login.adapter.SnickerDoodleAdapter in project instructure-android by instructure.
the class BaseLoginLandingPageActivity method setupSnickerDoodles.
/**
* Adds a simple login method for devs. To add credentials add your snickers (credentials) to the snickers.json
* Slide the drawer out from the right to have a handy one click login. FYI: Only works on Debug.
* Sample Format is:
*
* [
* {
* "password":"password",
* "subtitle":"subtitle",
* "title":"title",
* "username":"username",
* "domain":"about.blank"
* },
* ...
* ]
*/
private void setupSnickerDoodles() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerRecyclerView = (RecyclerView) findViewById(R.id.drawerRecyclerView);
boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
mDrawerLayout.setDrawerLockMode(isDebuggable ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
if (isDebuggable) {
Writer writer = new StringWriter();
try {
InputStream is = getResources().openRawResource(getResources().getIdentifier("snickers", "raw", getPackageName()));
char[] buffer = new char[1024];
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
is.close();
} catch (Exception e) {
// Do Nothing
}
String jsonString = writer.toString();
if (jsonString != null && jsonString.length() > 0) {
ArrayList<SnickerDoodle> snickerDoodles = new Gson().fromJson(jsonString, new TypeToken<ArrayList<SnickerDoodle>>() {
}.getType());
if (snickerDoodles.size() == 0) {
findViewById(R.id.drawerEmptyView).setVisibility(View.VISIBLE);
findViewById(R.id.drawerEmptyText).setVisibility(View.VISIBLE);
return;
}
mDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true));
mDrawerRecyclerView.setAdapter(new SnickerDoodleAdapter(snickerDoodles, new SnickerDoodleAdapter.SnickerCallback() {
@Override
public void onClick(SnickerDoodle snickerDoodle) {
mDrawerLayout.closeDrawers();
Intent intent = signInActivityIntent(snickerDoodle);
intent.putExtra(SNICKER_DOODLES, snickerDoodle);
startActivity(intent);
finish();
}
}));
} else {
findViewById(R.id.drawerEmptyView).setVisibility(View.VISIBLE);
findViewById(R.id.drawerEmptyText).setVisibility(View.VISIBLE);
}
}
}
Aggregations