This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListSelectorActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_list_selector) | |
setSupportActionBar(toolbar) | |
createViewPageAdapter() | |
fab.setOnClickListener { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChatAdapter(context: Context, | |
private val messages: List<ObMensage>, | |
private val onClick: RecyclerViewAdapter.RecyclerAdapterListener<ObMensage>?) : | |
RecyclerView.Adapter<ChatAdapter.Holder>() { | |
private val inflater: LayoutInflater = LayoutInflater.from(context) | |
private val textSending: String = context.getString(R.string.status_msg_sending) | |
private val textSent: String = context.getString(R.string.status_msg_sent) | |
private val textRead: String = context.getString(R.string.status_msg_read) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object GpxMath { | |
fun calculateGain(indexStartTrkPt: Int, trkPts: List<TrkPt>): Pair<Double, Double> { | |
var constMediaAccuracy = 0.0 | |
val size = trkPts.size | |
for (i in 0 until size) { | |
constMediaAccuracy += trkPts[i].accuracy | |
} | |
constMediaAccuracy /= size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Doc: https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner | |
belongs to Maven artifact "android.arch.lifecycle:extensions:1.1.1" (include in your dependences) | |
*/ | |
class MyApplication : Application(), LifecycleObserver { | |
override fun onCreate() { | |
super.onCreate() | |
ProcessLifecycleOwner.get().lifecycle.addObserver(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getDefaultPackageNameOfLauncher():String{ | |
PackageManager localPackageManager = getPackageManager(); | |
Intent intent = new Intent(Intent.ACTION_MAIN); | |
intent.addCategory(Intent.CATEGORY_HOME); | |
return localPackageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val intent = Intent(ChatActivity.ACTION_VIEW) | |
intent.putExtra(ChatActivity.PARAM_OBJECT, group) | |
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP | |
val pendingIntent = PendingIntent | |
.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) | |
// Activities: A(Main), B e C - O codigo acima gera uma nova activity B na mesma task, excluindo a B, C anterior. | |
// Manifest: Main activity: android:launchMode="singleTask" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected SwipeRefreshLayout swipe; | |
swipe = layout.findViewById(swipeId); | |
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | |
@Override | |
public void onRefresh() { | |
sendRequest(); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A interface funcional é declarada no método: | |
* myFuncionalInterface: (Int,String) -> Unit | |
* A interface acima tem como parametro um Int e uma String, ele é chamado como se fosse um método pelo proprio nome: | |
* myFuncionalInterface(1,"Sucesso") | |
*/ | |
fun methodFuncionalInterface(username: String, password: String, myFuncionalInterface: (Int,String) -> Unit) { | |
... | |
myFuncionalInterface(1,"Sucesso") | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws InterruptedException { | |
ExecutorService pool = Executors.newFixedThreadPool(2); | |
pool.submit(() -> { | |
try { | |
Thread.sleep(5000); | |
} catch (Exception e) { | |
} | |
System.out.println("5s"); | |
}); | |
pool.submit(() -> { |