├── .gitignore ├── .travis.yml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── tslamic │ │ └── devicenames │ │ ├── MainActivity.java │ │ └── RxActivity.java │ └── res │ ├── layout │ ├── activity_main.xml │ └── activity_rx.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── dn ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── dn.db.zip │ └── java │ │ └── com │ │ └── github │ │ └── tslamic │ │ └── dn │ │ ├── AndroidDeviceNames.kt │ │ ├── DeviceNames.kt │ │ ├── DeviceNamesDatabase.kt │ │ └── impl │ │ ├── AssetHandler.kt │ │ ├── Cache.kt │ │ ├── DeviceNamesDatabaseImpl.kt │ │ └── DeviceNamesImpl.kt │ └── test │ ├── java │ └── com │ │ └── github │ │ └── tslamic │ │ └── dn │ │ ├── AssetHandlerTest.kt │ │ ├── CacheTest.kt │ │ └── Utils.kt │ └── resources │ └── hello.txt.zip ├── generator └── generator.py ├── gradle.properties ├── gradle ├── gradle-mvn-push.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | android: 7 | components: 8 | - tools 9 | - tools 10 | - platform-tools 11 | - build-tools-26.0.1 12 | - android-26 13 | - extra-android-m2repository 14 | - extra-android-support 15 | 16 | licenses: 17 | - 'android-sdk-preview-license-.+' 18 | - 'android-sdk-license-.+' 19 | 20 | sudo: false 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android Device Names [![Build Status](https://travis-ci.org/tslamic/AndroidDeviceNames.svg?branch=master)](https://travis-ci.org/tslamic/AndroidDeviceNames) 2 | === 3 | 4 | This tiny Android library transforms a device model name into something people can understand. For example, a useless `SM-N910W8` becomes `Samsung Galaxy Note4` with a single method call. :tada: It currently recognizes about 15k devices, including all [Google Play supported devices](https://support.google.com/googleplay/answer/1727131). 5 | 6 | **It does not require network connectivity, ever. No, really.** 7 | 8 | To use it, add the following to your list of dependencies: 9 | 10 | ```groovy 11 | compile 'com.github.tslamic:dn3:3.0' 12 | ``` 13 | 14 | There are two classes you can use: 15 | 16 | 1. `DeviceNames` use this if all you need is a *single* query. 17 | 2. `DeviceNamesDatabase` for multiple queries. Don't forget to close it afterwards! 18 | 19 | RxJava2 is supported out of the box. Obtaining a `DeviceNames` instance is easy: 20 | 21 | ```java 22 | AndroidDeviceNames.deviceNames(context) 23 | .subscribeOn(Schedulers.io()) 24 | .observeOn(AndroidSchedulers.mainThread()) 25 | .subscribe(names -> doSomethingWith(names)); 26 | ``` 27 | 28 | but good ol' callbacks are supported too, in case you don't feel reactive: 29 | 30 | ```java 31 | AndroidDeviceNames.deviceNames(context, 32 | new AndroidDeviceNames.Callback() { 33 | @Override 34 | public void onReady(@NonNull DeviceNames instance) { 35 | String name = instance.currentDeviceName(); 36 | } 37 | }); 38 | ``` 39 | 40 | You can obtain an instance of `DeviceNamesDatabase` in a similar fashion. After you're done using it, don't forget to explicitly call `close()`. For example: 41 | 42 | ```java 43 | @Override 44 | protected void onStart() { 45 | super.onStart(); 46 | AndroidDeviceNames.deviceNamesDatabase(this, 47 | new AndroidDeviceNames.Callback() { 48 | @Override 49 | public void onReady(@NonNull DeviceNamesDatabase instance) { 50 | database = instance; 51 | } 52 | }); 53 | } 54 | 55 | @Override 56 | protected void onStop() { 57 | super.onStop(); 58 | if (database != null) { 59 | database.close(); 60 | } 61 | } 62 | ``` 63 | 64 | Both `DeviceNames` and `DeviceNamesDatabase` come with three methods: 65 | 66 | | method | description | 67 | | -----: | :---------- | 68 | | `currentDeviceName()` | Returns a user-friendly current device name, or `null` if the model is unknown. | 69 | | `currentDeviceName(String fallback)`| Same as above, but returns `fallback` if the model is unknown. | 70 | | `deviceName(String model, String fallback)` | Returns a user-friendly name for the specified `model`, or `fallback`, if model is unknown. | 71 | 72 | ### Not backwards compatible with v1 or v2, sorry. 73 | 74 | If you've been using AndroidDeviceNames v1 or v2, please note that this version is not backwards compatible. 75 | Updating should be trivial, result in minimal code change and is highly encouraged. 76 | 77 | ### Contributions 78 | 79 | Special thanks to [@corcoran](https://github.com/corcoran) for making numerous improvements to the lib. 80 | 81 | ### In the wild 82 | 83 | Here's the list of apps using this lib: 84 | 85 | - [XDA Labs](https://www.xda-developers.com/xda-labs) 86 | 87 | If you're using it in your app, and want to be on the above list, please let me know (create a pull request or open an issue). 88 | 89 | License 90 | --- 91 | 92 | Copyright 2017 Tadej Slamic 93 | 94 | Licensed under the Apache License, Version 2.0 (the "License"); 95 | you may not use this file except in compliance with the License. 96 | You may obtain a copy of the License at 97 | 98 | http://www.apache.org/licenses/LICENSE-2.0 99 | 100 | Unless required by applicable law or agreed to in writing, software 101 | distributed under the License is distributed on an "AS IS" BASIS, 102 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 103 | See the License for the specific language governing permissions and 104 | limitations under the License. 105 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.1" 6 | defaultConfig { 7 | applicationId "com.github.tslamic.devicenames" 8 | minSdkVersion 14 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation 'com.android.support:appcompat-v7:26.0.2' 25 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' 26 | implementation project(':dn') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/tslamic/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/tslamic/devicenames/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.tslamic.devicenames; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.EditText; 8 | import android.widget.TextView; 9 | 10 | import com.github.tslamic.dn.AndroidDeviceNames; 11 | import com.github.tslamic.dn.DeviceNamesDatabase; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | private DeviceNamesDatabase database; 15 | private TextView title; 16 | private EditText query; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | title = findViewById(R.id.title); 23 | query = findViewById(R.id.query); 24 | } 25 | 26 | @Override 27 | protected void onStart() { 28 | super.onStart(); 29 | AndroidDeviceNames.deviceNamesDatabase(this, 30 | new AndroidDeviceNames.Callback() { 31 | @Override 32 | public void onReady(DeviceNamesDatabase instance) { 33 | database = instance; 34 | } 35 | }); 36 | } 37 | 38 | @Override 39 | protected void onStop() { 40 | super.onStop(); 41 | if (database != null) { 42 | database.close(); 43 | } 44 | } 45 | 46 | @SuppressWarnings("UnusedParameters") 47 | public void query(View view) { 48 | if (database != null) { 49 | final String model = query.getText().toString(); 50 | final String name = database.deviceName(model, "unknown"); 51 | title.setText(name); 52 | } 53 | } 54 | 55 | @SuppressWarnings("UnusedParameters") 56 | public void rxExample(View view) { 57 | final Intent intent = new Intent(this, RxActivity.class); 58 | startActivity(intent); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/tslamic/devicenames/RxActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.tslamic.devicenames; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.TextView; 8 | 9 | import com.github.tslamic.dn.AndroidDeviceNames; 10 | import com.github.tslamic.dn.DeviceNames; 11 | 12 | import io.reactivex.android.schedulers.AndroidSchedulers; 13 | import io.reactivex.functions.Consumer; 14 | import io.reactivex.functions.Function; 15 | import io.reactivex.schedulers.Schedulers; 16 | 17 | public class RxActivity extends AppCompatActivity { 18 | private TextView text; 19 | 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_rx); 24 | text = findViewById(R.id.rx_text); 25 | } 26 | 27 | @Override 28 | protected void onStart() { 29 | super.onStart(); 30 | final Context context = this; 31 | AndroidDeviceNames.deviceNames(context) 32 | .subscribeOn(Schedulers.io()) 33 | .observeOn(AndroidSchedulers.mainThread()) 34 | .map(new Function() { 35 | @Override 36 | public String apply(DeviceNames deviceNames) throws Exception { 37 | return deviceNames.currentDeviceName("unknown"); 38 | } 39 | }) 40 | .subscribe(new Consumer() { 41 | @Override 42 | public void accept(String s) throws Exception { 43 | text.setText(String.format("This device name is %s", s)); 44 | } 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | 18 | 23 | 24 |