Why when I do sbt compile it doesn't print Hello?
// build.sbt
enablePlugins(Hello)
// project/Hello.scala
import sbt._
import sbt.Keys._
object Hello extends AutoPlugin {
object autoImport extends AnyRef {
lazy val hello = taskKey[Unit]("Says hello")
}
import autoImport._
override val projectSettings = Seq(
hello := {
streams.value.log.info("Hello")
},
compile in Compile := (compile in Compile).dependsOn(hello).value
)
Cheers
Here is the answer from https://stackoverflow.com/users/463761/dale-wijnand:
The problem is that you're defining compile in Compile which then gets
over-written by JvmPlugin.
To do what you want you need to make your
AutoPlugin require the JvmPlugin:
object Hello extends AutoPlugin {
override def requires = plugins.JvmPlugin
// etc
}
Related
I'm working in Kotlin and using retrofit. I have a recycler view, which consists of cards. Each card has a typeName and an image associated to it which for now I have added statically using dataclass. Now, I need to pass the typeName only from the CategoryFragment to the LocationFragment once the user clicks on a particular card. And at the LocationFragment I want to check the latitude, longitude and typeName from the database if it already exists.
Here's my code for the dataclass of Category:
data class Category_dataclass ( val category_image : Int , val typeName: String)
Here's my code for the CategoryFragment:
package com.example.atry.MakeComplaint
import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.atry.History.Complaints
import com.example.atry.History.MyComplainRecyclerViewAdapter
import com.example.atry.R
import kotlinx.android.synthetic.main.existing_complaint_popup.*
class CategoryFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val v = inflater.inflate(R.layout.fragment_category, container, false)
val recyclerView = v.findViewById(R.id.category_list) as RecyclerView
recyclerView.apply {
layoutManager = GridLayoutManager(context!!, 2)
}
//creating an arraylist to store category using the data class user
val category = ArrayList<Category_dataclass>()
//adding some dummy data to the list of categories
category.add(Category_dataclass((R.drawable.trash) , "Water"))
category.add(Category_dataclass((R.drawable.fire) , "Sewerage"))
category.add(Category_dataclass((R.drawable.dustbin) , "load"))
//creating our adapter
val adapter = CategoryRecyclerViewAdapter(category)
//now adding the adapter to recyclerview
recyclerView.adapter = adapter
// Inflate the layout for this fragment
return v
}
}
Here's the CategoryRecyclerViewAdapter:
package com.example.atry.MakeComplaint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.example.atry.History.ComplaintDetailsFragment
import com.example.atry.History.Complaints
import com.example.atry.MakeComplaint.Category_dataclass
import com.example.atry.MakeComplaint.CategoryRecyclerViewAdapter
import com.example.atry.R
import java.util.*
import kotlin.collections.ArrayList
class CategoryRecyclerViewAdapter(val categoryList: ArrayList<Category_dataclass>) : RecyclerView.Adapter<CategoryRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryRecyclerViewAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.fragment_category_single, parent, false)
return ViewHolder(v)
}
//this method is binding the data on the list
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindItems(categoryList[position])
holder.mView.setOnClickListener{view->
val lFragment = LocationFragment()
val oldFragment = CategoryFragment()
val manager = (holder.mView.context as AppCompatActivity).supportFragmentManager
val transaction = manager.beginTransaction()
transaction.replace(
R.id.first_screen_of_makecomplaint,
lFragment
) // give your fragment container id in first parameter
transaction.show(lFragment)
transaction.hide(oldFragment)
transaction.isAddToBackStackAllowed
transaction.addToBackStack(oldFragment.fragmentManager.toString()) // if written, this transaction will be added to backstack
transaction.commit()
}
}
//this method is giving the size of the list
override fun getItemCount(): Int {
return categoryList.size
}
inner class ViewHolder(val mView : View) : RecyclerView.ViewHolder(mView) {
fun bindItems(cat:Category_dataclass) {
val imageViewName = mView.findViewById(R.id.category_image) as ImageView
val textViewtext = mView.findViewById(R.id.category_text) as TextView
imageViewName.setImageResource(cat.category_image)
textViewtext.text = cat.typeName
}
}
}
And this is my retrofit:
//to check existing complaint
#GET("api/existingComplain")
#FormUrlEncoded
fun checkExistingComplain(#Query("typeName") typeName:String,
#Query("longitude") longitude:String,
#Query("latitude") latitude:String):Observable<Observables.checkExistingResult>
I've created and object where i stored the dataclass which will return the following:
data class checkExistingResult(val description:String , val Complain:String)
if the typeName and location already exists in the database I want the description and Complain to be displayed on a material styled dialog.
You can try this:
1st Step:-
val dashboard = "Dashboard"
take variable like this you can take it's name as your fragment name so page name you can check like this MainActivity().dashboard
Now, 2nd Step:-
create one class and write function like this in that class
fun openPage(
activity: Activity,
pagename: String?, model: PaymentDetails
) {
when (pagename) {
MainActivity().dashboard -> {
val mfragment = DashboardFragment()
(activity as MainActivity).fragmentManager.beginTransaction()
.replace(R.id.nav_host, mfragment).commit()
val a = Bundle()
a.putSerializable("model", model)
mfragment.arguments = a
}
}
}
take key value pair as I take my whole model and key is model in my code you can write any thing.
3rd Step:-
Make your model Serializable
4th Step:- When you are adding your values into model add details and add your model for method in which you want to use these values like following
val payment = PaymentDetails(
type,
price,
name,
id,
)
paymentData!!.add(payment)
CustomMethods().openPagePaymentDetails(
activity!!,
MainActivity().sessionPaymentFragment, payment
)
5th Step:-
Declare and initialise your object with type of your model like following:
//Declare
private var model: PaymentDetails? = null
//initialise
model = arguments!!.getSerializable("model") as PaymentDetails?
And now finally you can access value of previous fragment into your next fragment like this,
var type: String
type = model!!.type
Note:- please do no forgot to make your model class Serializable
Hope so it will help you.
I have a window application that i have developed in flex sdk 4.6 . I have the same version in web based application. In this application i am loading external swf font file. In web application everything is working fine but font is not loaded in window application.
Below is the code for loading the fonts..
package com
{
import adobe.utils.CustomActions;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.text.Font;
import injectors.CentralInjector;
import mx.core.FontAsset;
public class LF extends EventDispatcher
{
public function LF()
{
}
public function avaliable(style:String):Boolean{
var embeddedFonts:Array = Font.enumerateFonts(false);
for(var i:Number = 0; i < embeddedFonts.length; i++){
var item:Font = embeddedFonts[i];
if(item.fontStyle==style){
return true;
}
}
return false;
}
public function load(url:String):void{
//=====url is http://www.mydomain.com/font1.swf=================
CustomWaitAlert.show(CustomWaitAlert.WAIT,null,"Loading fonts...");
var loader:Loader = new Loader();
var loaderInfo:LoaderInfo = loader.contentLoaderInfo;
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
loaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest(url));
}
private function ioerror(evt:IOErrorEvent):void{
this.dispatchEvent(new Event("IOERROR"));
}
private function onLoadComplete(evt:Event):void{
var embeddedFonts:Array = Font.enumerateFonts(false);
this.dispatchEvent(new Event("COMPLETE"));
CustomWaitAlert.hide();
}
}
}
The solution i got is to first load the font swf via url loader then we get the bytearray.after that just load tge bytearray with the loader class with loading context which is having allowcodeimport sets to true...
I am trying to build a pure as3 project in flex and I got the following error:
type was not found or was not a compile-time constant: Button
type was not found or was not a compile-time constant: TextField
My code is:
import fl.controls.TextInput; // import my textinput
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.text.TextField;
import fl.controls.Button; //import my button
public class SearchYoutube extends Sprite
{
private var textBx:TextField=new TextField();
private var controls:Controls;
private var bground:Sprite=new Sprite();
private var searchButton:Button;
/************************Constructor*********************/
public function SearchYoutube()
{
/*********************Create Search Form****************************/
createSearchForm("Please Enter Your Keyword");
}
/*********************Search Form****************************/
private function createSearchForm(title:String):void{
var searchInput:TextInput = new TextInput(); //error here
searchInput.width = 200;
searchInput.x=150;
searchInput.y=450;
searchKeyword=searchInput.text;
addChild(searchInput);
searchButton = new Button(); //error here
searchButton.x = 380;
searchButton.y = 450;
searchButton.label = "Search";
addChild(searchButton);
}
}
}
I appreciate any helps!
Agree with the above answer, and add that Button is in package mx.controls.
Use imports
import mx.controls.Button;
import mx.controls.TextInput;
Also to address other comments, doesn't "actionscript only" just mean no mxml and .mxml files? It's still a .as files only.
Haven't done any Flash coding for a while, but I seem to remember that all of the fl. Your Flex Builder can't see those two classes. Scrolling through the language reference there is no fl package, so I would say you need to change those two classes to something that exists in Flex like flash.display.Sprite (with buttonMode on) and flash.text.TextField
http://livedocs.adobe.com/flex/3/langref/
I'm wondering if I can dynamically embed fonts in Flex. I want to embed different fonts for different users so I don't want to embed all possible fonts in the same Flex file. If it's possible could you please post sample code.
You can do this in Actionscript. I've used this trick primarily to use opentype fonts that weren't supported with the compiler in the Flash IDE and to create font libraries that could be loaded lazily (only when needed), but you can also use this to selectively load fonts. If you had the mxmlc compiler on your server you could even generate the fontlib.as file and compile it on command.
// fontlib.as
// font library file
package {
import flash.display.Sprite;
public class fontlib extends Sprite {
[Embed(source = 'font/path/FontFile.otf', fontName = 'FontFile', unicodeRange = 'U+0020-U+007E,U+00AB,etc...')]
public static var FontFile:Class;
public static const FontFile_name:String = "FontFile"; // matches 'fontName' in embed
public function fontlib() {
}
}
}
This can be compiled like so:
mxmlc fontlib.as
You can use in your application like this:
// Main.as
// document class
package {
import flash.text.Font;
import flash.display.Loader;
import flash.events.Event;
import flash.system.ApplicationDomain;
import flash.text.StyleSheet;
public var fontsLoader:Loader;
public var fontFile:String = "";
public var ss:StyleSheet;
public function Main() {
fontsLoader = new Loader();
fontsLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onFontsLoadComplete);
}
private function _onFontsLoadComplete(e:Event):void {
var fontlib:Class = e.target.applicationDomain.getDefinition('fontlib');
Font.registerFont(fontlib.FontFile); // registers font
fontFile = fontlib.FontFile_name; // name the font was loaded as
// actually using the font looks like this:
ss = new StyleSheet();
ss.parseCSS("div { fontFamily: " + fontFile + "; }");
}
}
I have a very simple practice program for Flex 4 ( Gumbo ).
package
{
import mx.controls.ColorPicker;
import mx.controls.Label;
import mx.events.ColorPickerEvent;
import flash.display.Sprite;
public class testClass extends Sprite
{
private var cPicker:ColorPicker = new ColorPicker();
private var lbl:Label;
public function testClass()
{
cPicker.addEventListener(ColorPickerEvent.CHANGE,
colorPicker_change);
cPicker.move(10, 10);
addChild(cPicker);
lbl = new Label();
lbl.text = cPicker.hexValue;
lbl.move(10, 40);
addChild(lbl);
}
private function colorPicker_change(evt:ColorPickerEvent):void
{
lbl.text = cPicker.hexValue; // ff0000
}
}
}
But after building with 'mxmlc.exe testClass.as' on the command line, I get...
C:\src>mxmlc testClass.as Loading configuration file
C:\flex_sdk_4\frameworks\flex-config.xml
C:\src\testClass.as(21): col:
32 Error: Access of possibly undefined
pro perty hexValue through a reference
with static type
mx.controls:ColorPicker.
lbl.text = cPicker.hexValue;
^
C:\src\testClass.as(28): col:
32 Error: Access of possibly undefined
pro perty hexValue through a reference
with static type
mx.controls:ColorPicker.
lbl.text = cPicker.hexValue; // ff0000
^
Why does it think that cPicker is static? Or that cPicker.hexValue is undefined?
Also it seems that even after importing the ColorPicker library in the code using the import keyword, I somehow have to import it on the commandline for building as well. Is that correct?
According to my reading of the documentation hexValue isn't a property available on the ColorPicker. Do you mean selectedColor?