Skip to content

Instantly share code, notes, and snippets.

View manijshrestha's full-sized avatar

Manij Shrestha manijshrestha

View GitHub Profile
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<device-owner package="com.manijshrestha.lollipopkiosk" name="Task Pinning" />
package com.manijshrestha.lollipopkiosk;
import android.app.admin.DeviceAdminReceiver;
import android.content.ComponentName;
import android.content.Context;
public class BasicDeviceAdminReceiver extends DeviceAdminReceiver {
<receiver
android:name=".BasicDeviceAdminReceiver"
android:label="@string/admin_permission_label"
android:description="@string/admin_permission_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
private void provisionOwner() {
DevicePolicyManager manager =
(DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = BasicDeviceAdminReceiver.getComponentName(this);
if(!manager.isAdminActive(componentName)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
startActivityForResult(intent, 0);
@Override
public void onBackPressed() {
stopLockTask();
}
productFlavors {
demo {
applicationId = "com.manijshrestha.weatherdemo.demo"
resValue "string", "app_name", "Demo App"
}
full {
applicationId = "com.manijshrestha.weatherdemo.full"
resValue "string", "app_name", "Full App"
}
}
public class WeatherService {
private WeatherListener mListener;
public WeatherService(WeatherListener listener) {
this.mListener = listener;
}
public void getWeather(String cityName) {
RestAdapter adapter = new RestAdapter.Builder().setEndpoint("http://api.openweathermap.org").build();
@manijshrestha
manijshrestha / build.gradle
Last active June 3, 2017 04:16
Include Room
dependencies {
....
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha1"
...
}
import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey
@Entity(tableName = "task")
data class Task(@ColumnInfo(name = "completed_flag") var completed: Boolean = false,
@ColumnInfo(name = "task_desciption") var description: String) {
@ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true) var id: Long = 0
}
@Dao interface TaskDao {
@Query("select * from task")
fun getAllTasks(): List<Task>
@Query("select * from task where id = :p0")
fun findTaskById(id: Long): Task
@Insert(onConflict = REPLACE)
fun insertTask(task: Task)