Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main
- ======
- package whatsapp.com.example.android.julian.newapp;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.PersistableBundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- /**
- * Created by android on 09/01/2017.
- */
- public class MainActivity extends AppCompatActivity {
- Button btnLogin, btnRegister;
- EditText txtName, txtPass;
- TextView ttlLogo;
- Context context;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer2();
- Backendless.initApp(this,
- getResources().getString(R.string.app_id),
- getResources().getString(R.string.android_id),
- getResources().getString(R.string.app_v));
- }
- private void setPointer2()
- {
- this.context=this;
- btnLogin = (Button) findViewById(R.id.btnLogin);
- btnRegister = (Button) findViewById(R.id.btnRegister);
- txtName = (EditText) findViewById(R.id.txtUserName);
- txtPass = (EditText) findViewById(R.id.txtUserPassword);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String uName, uPass;
- uName = txtName.getText().toString();
- uPass = txtPass.getText().toString();
- if (uName.length() < 1 || uPass.length() < 1) {
- Toast.makeText(context, "you must provide user and password", Toast.LENGTH_SHORT).show();
- return;
- }
- Backendless.UserService.login(uName, uPass, new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- startActivity(new Intent(context, MainActivity2.class));
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(context, "Error:" + fault.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- });
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(context, Register.class));
- }
- });
- }
- }
- =======
- main2
- ======
- package whatsapp.com.example.android.julian.newapp;
- import android.Manifest;
- import android.app.ProgressDialog;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.database.Cursor;
- import android.provider.ContactsContract;
- import android.support.design.widget.FloatingActionButton;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- import java.util.ArrayList;
- import java.util.Collections;
- public class MainActivity2 extends AppCompatActivity {
- private static String TAG = "Permissions";
- private static final int CONTACTS_REQUEST_CODE = 101;
- Context context;
- ListView list;
- ArrayList<String> phoneContactList;
- FloatingActionButton fab;
- Adapter myAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.contacts);
- requestPermissions();
- setPointer();
- }
- private void makeRequest() {
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS}, CONTACTS_REQUEST_CODE);
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- switch (requestCode) {
- case CONTACTS_REQUEST_CODE:
- if (grantResults.length > 0 || grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- Log.i(TAG, "onRequestPermissionsResult: Permission Granted");
- } else {
- Log.i(TAG, "onRequestPermissionsResult: Permission Denied");
- }
- return;
- }
- }
- private void requestPermissions() {
- int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS);
- if (permission != PackageManager.PERMISSION_GRANTED) {
- Log.i(TAG, "onCreate: Permission to record denied");
- {
- if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage("Permission to access the CONTACTS is required for this app.")
- .setTitle("Permission required");
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- Log.i(TAG, "onClick: Clicked");
- makeRequest();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- } else {
- makeRequest();
- }
- }
- }
- }
- private void setPointer() {
- this.context = this;
- fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- final EditText myTxt = new EditText(context);
- myTxt.setHint("הכנס שם");
- new AlertDialog.Builder(context)
- .setTitle("הכנס את פרטי המוזמן")
- .setPositiveButton("OK",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- myAdapter.addFriend(myTxt.getText().toString());
- dialog.dismiss();
- }
- })
- .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- })
- .setIcon(android.R.drawable.ic_dialog_alert)
- .setView(myTxt)
- .show();
- }
- });
- ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("טוען אנשי קשר....");
- pd.show();
- phoneContactList = new ArrayList<>();
- list = (ListView) findViewById(R.id.list);
- ContentResolver cr = getContentResolver();
- Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
- if (cur.getCount() > 0) {
- while (cur.moveToNext()) {
- String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
- String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
- if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
- Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
- while (pCur.moveToNext()) {
- phoneContactList.add(name);
- Log.i("Contact List", name);
- }
- pCur.close();
- }
- }
- Collections.sort(phoneContactList);
- int cnt = phoneContactList.size();
- myAdapter = new Adapter(context, phoneContactList);
- list.setAdapter(myAdapter);
- pd.dismiss();
- }
- cur.close();
- }
- }
- =====
- adapter
- =====
- package whatsapp.com.example.android.julian.newapp;
- import android.app.AlertDialog;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.SharedPreferences;
- import android.database.Cursor;
- import android.provider.ContactsContract;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.BaseAdapter;
- import android.widget.CheckBox;
- import android.widget.ListView;
- import android.widget.Switch;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- /**
- * Created by android on 02/01/2017.
- */
- public class Adapter extends BaseAdapter {
- Context context;
- List<String> phoneContactList;
- public Adapter(Context context, List<String> friendsList) {
- this.context = context;
- this.phoneContactList = friendsList;
- }
- @Override
- public int getCount() {
- return phoneContactList.size();
- }
- @Override
- public Object getItem(int i) {
- return phoneContactList.get(i);
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(int i, View view, ViewGroup viewGroup) {
- View myInflatedView = LayoutInflater.from(context).inflate(R.layout.friend_item, null, false);
- TextView txtName = (TextView) myInflatedView.findViewById(R.id.txtName);
- final CheckBox mySwitch = (CheckBox) myInflatedView.findViewById(R.id.mySwitch);
- txtName.setText(phoneContactList.get(i));
- mySwitch.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
- builder.setMessage("Permission to access the CONTACTS is required for this app.")
- .setTitle("Permission required");
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- //public static final String TAG = ;
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- // Log.i(TAG, "onClick: Clicked");
- //makeRequest();
- }
- });
- android.support.v7.app.AlertDialog dialog = builder.create();
- dialog.show();
- mySwitch.setChecked(!mySwitch.isChecked());
- }
- });
- return myInflatedView;
- }
- public void addFriend(String friendName)
- {
- phoneContactList.add(friendName);
- notifyDataSetChanged();
- }
- }
- =========
- register
- ======
- package whatsapp.com.example.android.julian.newapp;
- import android.content.Context;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- public class Register extends AppCompatActivity {
- Button btnRegister, btnCancel;
- EditText txtUname, txtUpass, txtUpass2, uEmail, uPhone;
- TextView txtView;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer() {
- this.context = this;
- uPhone = (EditText) findViewById(R.id.txtPhone);
- btnCancel = (Button) findViewById(R.id.btnCancel);
- btnRegister = (Button) findViewById(R.id.btnRegisterUser);
- txtUname = (EditText) findViewById(R.id.txtUserName);
- txtUpass = (EditText) findViewById(R.id.txtPassword2);
- txtUpass2 = (EditText) findViewById(R.id.txtPassword3);
- uEmail = (EditText) findViewById(R.id.txtEmail);
- txtView = (TextView) findViewById(R.id.txtView);
- btnCancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- finish();
- }
- });
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (checkData()) {
- BackendlessUser newUser = new BackendlessUser();
- newUser.setEmail(uEmail.getText().toString());
- newUser.setPassword(txtUpass.getText().toString());
- newUser.setProperty("phone_number",uPhone.getText().toString());
- newUser.setProperty("user_name",txtUname.getText().toString());
- Backendless.UserService.register(newUser, new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- Toast.makeText(context, "User Registred...", Toast.LENGTH_SHORT).show();
- finish();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(context, "Error" + fault.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
- });
- }
- private boolean checkData() {
- //if user update fields
- if (txtUname.getText().toString().length() < 1 ||
- txtUpass2.getText().toString().length() < 1 ||
- txtUpass.getText().toString().length() < 1)
- {
- return false;
- }
- //if password are equals
- if (!txtUpass.getText().toString().equals(txtUpass2.getText().toString())) {
- Toast.makeText(context, "Password not match..", Toast.LENGTH_SHORT).show();
- return false;
- }
- return true;
- }
- }
- ======
- manifest
- =====
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="whatsapp.com.example.android.julian.newapp">
- <uses-permission android:name="android.permission.READ_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_CONTACTS" />
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".Register"/>
- <activity android:name=".MainActivity2"/>
- </application>
- </manifest>
- ======
- main.xml
- ====
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layoutDirection="rtl"
- android:orientation="vertical"
- android:textDirection="rtl"
- android:weightSum="1">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="170dp"
- android:text="Login"
- android:gravity="center"
- android:textSize="100sp">
- </TextView>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="100dp"
- android:orientation="vertical">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_user_name"
- android:inputType="text"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/txtUserPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_password"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical"
- android:layout_weight="0.53">
- <Button
- android:id="@+id/btnLogin"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="20dp"
- android:background="#00BFFF"
- android:text="@string/btn_login"
- android:textColor="#ffffff"
- android:textSize="32sp" />
- <Button
- android:id="@+id/btnRegister"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="50dp"
- android:background="#00BFFF"
- android:text="@string/Register_button"
- android:textColor="#ffffff"
- android:textSize="32sp" />
- </LinearLayout>
- </LinearLayout>
- ======
- register.xml
- =======
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layoutDirection="rtl"
- android:textDirection="rtl">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_user_name"
- />
- <EditText
- android:id="@+id/txtEmail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtUserName"
- android:hint="@string/enter_email" />
- <EditText
- android:id="@+id/txtPhone"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtEmail"
- android:hint="@string/enter_your_phone_number" />
- <EditText
- android:id="@+id/txtPassword2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPhone"
- android:hint="@string/enter_password" />
- <EditText
- android:id="@+id/txtPassword3"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword2"
- android:hint="@string/confirm_password" />
- <CheckBox
- android:id="@+id/checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/btnRegisterUser"
- android:layout_marginTop="10sp"
- android:text="אני מסכים" />
- <TextView
- android:id="@+id/txtView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/btnCancel"
- android:textColor="@color/colorPrimary"
- android:layout_marginRight="10sp"
- android:text="תנאי השימוש"
- android:textSize="15sp"
- />
- <Button
- android:id="@+id/btnRegisterUser"
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword3"
- android:layout_marginTop="35dp"
- android:text="@string/Register_button" />
- <Button
- android:id="@+id/btnCancel"
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword3"
- android:layout_marginTop="35dp"
- android:layout_toEndOf="@id/btnRegisterUser"
- android:text="@string/btn_cancel" />
- </RelativeLayout>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:gravity="center"
- android:text="הרשמה"
- android:textSize="32sp" />
- </LinearLayout>
- =====
- contacts.xml
- ====
- <android.support.design.widget.CoordinatorLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="true">
- <android.support.design.widget.FloatingActionButton
- android:id="@+id/fab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="end|bottom"
- android:layout_margin="@dimen/fab_margin"
- android:src="@drawable/fab_plus_icon" />
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:elevation="20dp"
- android:gravity="center"
- android:text="contacts"
- android:textSize="40sp" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="3sp"
- android:background="@color/colorPrimary" />
- <ListView
- android:id="@+id/list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"></ListView>
- </LinearLayout>
- </android.support.design.widget.CoordinatorLayout>
- ========
- item_friend.xml
- =======
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal" android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layoutDirection="rtl"
- android:layout_margin="10dp">
- <CheckBox
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/mySwitch"
- android:layout_gravity="center_vertical"/>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="SAMPLE TEXT"
- android:id="@+id/txtName"
- android:textSize="30sp"/>
- </LinearLayout>
- =======
- string.res
- =====
- <resources>
- <string name="button_text">asd</string>
- <string name="app_name">Cordinator</string>
- <string name="enter_user_name">הכנס/י שם משתמש....</string>
- <string name="enter_email">הכנס/י דואר אלקטרוני...</string>
- <string name="enter_your_phone_number">הכנס/י מספר נייד....</string>
- <string name="enter_password">הכנס/י סיסמא...</string>
- <string name="confirm_password">אשר/י סיסמא..</string>
- <string name="title_activity_register">Register</string>
- <string name="Register_button">הרשמה</string>
- <string name="btn_cancel">ביטול</string>
- <string name="btn_login">כניסה</string>
- <string name="app_id">66A2E76C-4E40-6695-FFCF-CD56DC334D00
- </string>
- <string name="app_v">v1</string>
- <string name="android_id">F554F240-A498-DC21-FFEC-792D1D8D1C00
- </string>
- </resources>
- =======
- grable
- =====
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
- buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:2.2.2'
- classpath 'com.android.tools.build:gradle:2.2.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
- task clean(type: Delete) {
- delete rootProject.buildDir
- }
- ======
- grable2
- ======
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 25
- buildToolsVersion "25.0.1"
- defaultConfig {
- applicationId "whatsapp.com.example.android.julian.newapp"
- minSdkVersion 19
- targetSdkVersion 25
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- compile 'com.android.support:appcompat-v7:25.1.0'
- testCompile 'junit:junit:4.12'
- compile 'com.scalified:fab:1.1.2'
- compile 'com.backendless:backendless:3.0.20.1'
- compile 'com.android.support:design:25.1.0'
- }
Add Comment
Please, Sign In to add comment