GithubHelp home page GithubHelp logo

dukererenst / android-clean-architecture-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from disono/android-clean-architecture-boilerplate

0.0 1.0 0.0 3.11 MB

Android Clean Architecture Boilerplate

License: Apache License 2.0

Java 100.00%

android-clean-architecture-boilerplate's Introduction

Android Clean Architecture Boilerplate

is a starting blank template for Android Projects

Libraries

Utilities Usage

Running Logic on Thread

MainThreadImp.getInstance().post(new Runnable() {
  @Override
  public void run() {
    
  }
});

Camera

@Inject
Launcher launcher;

int REQUEST_IMAGE_CAPTURE = launcher.REQUEST_IMAGE_CAPTURE;
launcher.takePicture();

// on activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
    Bundle extras = data.getExtras();
    Bitmap imageBitmap = (Bitmap) extras.get("data");
    if (imageBitmap != null) {
      // location: imageBitmap.toString()
    }
  }
}

Video

@Inject
Launcher launcher;

int REQUEST_VIDEO_CAPTURE = launcher.REQUEST_VIDEO_CAPTURE;
launcher.takeVideo();

// on activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
    // video file: launcher.videoFile(data);
  }
}

Accelerometer

@Inject
AccelListener accelListener;

// accelerometer
accelListener.listener(new SensorEventListener() {
  public void onSensorChanged(SensorEvent event) {
    // only look at accelerometer events
    if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
      return;
    }
    
    // X: event.values[0]
    // Y: event.values[1]
    // Z: event.values[2]
  }

  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) {

  }
});

// start
try {
  accelListener.start();
} catch (Exception e) {
  e.printStackTrace();
}

// stop
accelListener.stop();

GPS

@Inject
GPS gps;

// gps
gps.run(new LocationListener() {
  @Override
  public void onLocationChanged(Location location) {
    // LAT: location.getLatitude()
    // LNG: location.getLongitude()
  }

  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {

  }

  @Override
  public void onProviderEnabled(String provider) {

  }

  @Override
  public void onProviderDisabled(String provider) {

  }
});

Screen Orientation

@Inject
ScreenOrientation orientation;
    
// screen orientation
TYPES:
UNSPECIFIED, LANDSCAPE_PRIMARY, PORTRAIT_PRIMARY, LANDSCAPE, PORTRAIT, LANDSCAPE_SECONDARY, PORTRAIT_SECONDARY

try {
  orientation.apply(TYPES);
} catch (Exception e) {
  e.printStackTrace();
}

Vibration

@Inject
Vibrate vibrate;
    
long[] patterns = {100, 200, 300, 400, 500};
vibrate.pattern(patterns, 1);

Audio Player

@Inject
AudioHandler audioHandler;

// play audio
audioHandler.play("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.audio);

Video Player

@Inject
VideoHandler videoHandler;

videoHandler.play("https://www.youtube.com/path-to-video");
videoHandler.play("http://your-domain-name/video.mp4");
videoHandler.play("file:///your-path/demo.mp4");
videoHandler.play("file:///android_asset/your-path/demo.mp4");

Dialogs

// error dialog
DialogFactory.error(ctx, "Title", "Message!",
  new DialogInterfaceFactory().OnClick(new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
                      
    }
})).show();

Alerts

@Inject
WBAlerts wbAlerts;

wbAlerts.error("Error Name", "Error Message").show();

API Call

// Call API
YourAdapter yourAdapter = new YourAdapter();
Call<YOURMODELNAME> call = yourAdapter.getUser("username");
call.enqueue(new Callback<YOURMODELNAME>() {
  @Override
  public void onResponse(Call<YOURMODELNAME> call, Response<YOURMODELNAME> response) {
    final Response<YOURMODELNAME> res = response;
    
    // sample response model
    // res.body().getEmail()
  }
  
  @Override
  public void onFailure(Call<YOURMODELNAME> call, Throwable t) {
    
  }
});

SMTP

@Inject
SMTP smtp;

smtp.username = "[email protected]";
smtp.password = "your-password";

smtp.host = "smtp.gmail.com";

// single email
smtp.email = "[email protected]";
// multiple email
smtp.emailMultiple = "[email protected],[email protected]";

smtp.subject = "JavaMail Demo";
smtp.message = "Content of the demo";

smtp.attachment = new File(Environment.getExternalStorageDirectory() +
  File.separator + "DCIM" + File.separator + "Camera" + File.separator + "your-image.png").toString();

// send the email
smtp.execute();

IMAP

@Inject
IMAP imap;

private class FetchEmail extends AsyncTask<Void, Void, Void> {
  @Override
        protected Void doInBackground(Void... voids) {
            imap.username = "[email protected]";
            imap.password = "your-email-password";

            imap.host = "imap.your-provider.com";

            IMAP.ContentMessages[] messages = imap.fetch();
            for (IMAP.ContentMessages message : messages) {
              // message.getReceivedDate().toString()
            }

            // close the connection
            imap.close();

            return null;
        }
}

// execute the task
new FetchEmail().execute();

Network Connection Type

@Inject
Network network;

// type
network.connectionInfo().getString("type");
// info
network.connectionInfo().getString("info");

SocketIO

@Inject
SocketIOConnector socketIOConnector;

socketIOConnector.setUp();
// response
Emitter.Listener onNewMessage = args -> mActivity.runOnUiThread(() -> {
    String response = (String) args[0];
    Log.i(TAG, "Response: " + response);
});
socketIOConnector.listen("recieved_message", onNewMessage);

// connect
socketIOConnector.connect();

// sent data, message or what ever you
socketIOConnector.sendString("send_message", "We will sent data here!");

FireBase Cloud Messaging

Replace the google-service.json under app folder with your own.

SIP Phone

// start SIP Service
startService(new Intent(getBaseContext(), SIPService.class));

// stop SIP Service
stopService(new Intent(getBaseContext(), SIPService.class));

// start a call
new SIPService().initiateCall(mActivity, "sip:name_to_call@domain");

Helpers

File helpers
FileWBFile.getBmpUri(Context context, Bitmap inImage);
String WBFile.getRealPathFromURI(Activity activity, Uri uri);
File WBFile.bmpToFile(Activity activity, Bitmap bitmap);

Form helpers
Spinner WBForm.defaultSpinner(Context context, int spinnerArray, Spinner spinner, AdapterView.OnItemSelectedListener onItemSelectedListener);

HTTP helpers
void WBHttp.imgURLLoad(Context context, String source, CircleImageView imageView);

Security helpers
String WBSecurity.MD5(String toHash);
String WBSecurity.encodeBase64(String toConvert);
String WBSecurity.decodeBase64(String converted);

Encryption helpers
String JWT.generateToken();

Time helpers
long WBTime.unix();
long WBTime.unixTimeStamp();
long WBTime.addMinuteUnix(int minute);
Date WBTime.currentDate();
Date WBTime.addMinuteDate(int minute);
Date WBTime.minusMinuteDate(int minute);
String WBTime.getMonthForInt(int num);

Other Resources

Using OAuth 2.0 with the Google API Client Library for Java

License

Android Clean Architecture Boilerplate is licensed under the Apache License (ASL) license. For more information, see the LICENSE file in this repository.

android-clean-architecture-boilerplate's People

Contributors

disono avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.