Skip to content

Instantly share code, notes, and snippets.

View barmgeat's full-sized avatar

Mustafa Hazim barmgeat

  • Berlin, Germany
View GitHub Profile
@barmgeat
barmgeat / AA Transition App theme between light and dark themes
Last active September 14, 2018 22:21 — forked from willu2/AA Transition App theme between light and dark themes
Example of how to change themes at runtime with a smooth animation. In this example, we just switch between a light and a dark theme. The activity animation is defined in the theme and as such will be default on all activities with the set theme. [Demo Video here](http://youtu.be/Ps0phswbHls). See more at : https://android.jlelse.eu/android-chan…
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class TransitionThemeActivity extends AppCompatActivity implements View.OnClickListener {
package com.example.AppName.new_package_name;
import android.provider.BaseColumns;
public final class ContractClass {
// content Uri
public static final String CONTENT_AUTHORITY = "com.example.android.AppName";
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
public static final String PATH_WORDS = "words";
@barmgeat
barmgeat / HelperClass.java
Last active September 15, 2018 00:22
SQLite Helper Class
public class HelperClass extends SQLiteOpenHelper {
//Name of the database
private static final String DATABASE_NAME = "DBName.db";
//DB Version
private static final int DATABASE_VERSION = 1;
@barmgeat
barmgeat / MainActivity.java
Last active September 15, 2018 00:48
Insert Opration SQLite
public class MainActivity extends AppCompatActivity {
private HelperClass mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHelper = new HelperClass(this);
@barmgeat
barmgeat / AppProvider.java
Last active September 15, 2018 20:40
Provider SQLite Android Content Provider
public class AppProvider extends ContentProvider {
private HelperClass mDbHelper;
@Override
public boolean onCreate() {
mDbHelper = new HelperClass(getContext());
return true;
}
@barmgeat
barmgeat / Manifest.xml
Last active September 15, 2018 05:07
Add the Provider to the Manifest
<provider
android:authorities="com.example.android.AppName"
android:name=".Data.AppProvider"
android:exported="false" />
public class AppProvider extends ContentProvider {
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
static {
/*
* The calls to addURI() go here, for all of the content URI patterns that the provider
* should recognize. For this snippet, only the calls for table 3 are shown.
*/
@barmgeat
barmgeat / AppProvider.java
Created September 15, 2018 19:15
Implemt the query() Method SQLit Content Provider
...
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
// Get readable database
SQLiteDatabase database = mDbHelper.getReadableDatabase();
// This cursor will hold the result of the query
Cursor cursor=null;
// Figure out if the URI matcher can match the URI to a specific code
...
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
final int match = uriMatcher.match(uri);
switch (match){
case WORDS_CODE :
return insertData(uri, contentValues);
default:
public void insertData() {
ContentValues values = new ContentValues();
values.put(Words.COLUMN_WORD, "Test Word");
values.put(Words.COLUMN_WORD_T, "Test T Word");
values.put(Words.COLUMN_WORD_T2, "Test T2 Word");
values.put(Words.COLUMN_WORD_T3, "Test T3 Word");
values.put(Words.COLUMN_ARTIKEL, Words.ARTIKEL_UNKNOWN);
Uri newURI = getContentResolver().insert(DeutchVContract.CONTENT_URI, values);
if (newURI != null) {